#!/bin/bash
root_dir=/opt/playweb
runjob(){
  sudo -u nginx $root_dir/bin/play-scala-seed -J-Xms1g -J-Xmx1g -Dhttp.port=9000 -Dconfig.resource=application.conf  > $root_dir/logs/log_$(date +%Y%m%d).txt &
}
if test -x $root_dir/bin/play-scala-seed
then 
	case $1 in
	"start")
		if test -e $root_dir/RUNNING_PID
		then
		echo "stoping..."
		kill $(cat $root_dir/RUNNING_PID)
		echo "stoped."
		fi
	echo "starting..."
	#sudo -u nginx $root_dir/bin/play-scala-seed -J-Xms1g -J-Xmx1g -Dhttp.port=9000 -Dconfig.resource=application.conf  > $root_dir/log.txt &
	runjob
	echo "started."
	;;
	"stop")
	echo "stoping..."
	kill $(cat $root_dir/RUNNING_PID)
	echo "stoped."
	;;
	"restart")
	echo "stoping..."
	kill $(cat $root_dir/RUNNING_PID)
	echo "stoped."
	echo "starting..."
	#sudo -u nginx $root_dir/bin/play-scala-seed -J-Xms1g -J-Xmx1g -Dhttp.port=9000 -Dconfig.resource=application.conf  > $root_dir/log.txt &
  runjob
	echo "started."
	;;
	*)
	echo "Please shell run.sh (start | stop | restart)"
	;;
esac
else
	echo "the shell is not exist."
fi

